package com.yanxu.design01_singleton.destroy.serialize_destory;

import java.io.*;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025/4/14-2025
 * @Description: 使用序列化的方式破坏坏单例模式
 */
public class LazyTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        LazyInstance lazyInstance = LazyInstance.getInstance();
        System.out.println("lazyInstance = " + lazyInstance);

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("lazy_singleton_file"));
        oos.writeObject(lazyInstance);

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("lazy_singleton_file"));
        LazyInstance lazyInstance2 = (LazyInstance) ois.readObject();
        System.out.println("lazyInstance2 = " + lazyInstance2);

        System.out.println(lazyInstance == lazyInstance2);
    }
}